#include "dialogfilter.h"
#include "ui_dialogfilter.h"
#include "dialogfilteritem.h"
#include <QStandardItemModel>
DialogFilter::DialogFilter(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::DialogFilter)
{
    ui->setupUi(this);
    QStandardItemModel *model = new QStandardItemModel(0, 2, this);
    model->setHeaderData(0, Qt::Horizontal, QApplication::translate("aboutDialog", "filter name", 0, QApplication::UnicodeUTF8) );
    model->setHeaderData(1, Qt::Horizontal, QApplication::translate("aboutDialog", "rule", 0, QApplication::UnicodeUTF8));
    ui->lvw_rule->setModel(model);
}

DialogFilter::~DialogFilter()
{
    delete ui;
}

void DialogFilter::changeEvent(QEvent *e)
{
    QDialog::changeEvent(e);
    switch (e->type()) {
    case QEvent::LanguageChange:
        ui->retranslateUi(this);
        break;
    default:
        break;
    }
}

void DialogFilter::on_btnAdd_clicked()
{
    DialogFilterItem dl;//= new DialogFilterItem();
    dl.setModal(true);
    int r = dl.exec();
    if(r == QDialog::Accepted)
    {
        QList<string> f = dl.filterItemString;
        int i =0;
        QStandardItemModel *model = ( QStandardItemModel *)this->ui->lvw_rule->model();
        QList<QStandardItem*> items;// = new QList<QStandardItem*>;


        QStandardItem* item1 = new QStandardItem( QString(f[0].c_str()) );
        QStandardItem* item2 = new QStandardItem( QString(f[1].c_str()) );
        items.append( item1);
        items.append(item2);

        model->appendRow( items );
    }
}
